package com.neu.fenli2023623.security;

import com.neu.fenli2023623.entity.User;
import com.neu.fenli2023623.service.UserService;
import com.neu.fenli2023623.vo.RightVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserService userService;
    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
        User User = userService.selectByAccount(account);
        List<RightVo> rightVos = userService.selectRightByAccount(account, 0);
        String[] permission = userService.selectPermissionByAccount(account);
        String[] role = userService.selectRoleByAccount(account);
        LoginUser userDetails = new LoginUser();
        userDetails.setUser(User);
        userDetails.setRightVos(rightVos);
        userDetails.setPermissions(permission);
        userDetails.setRoles(role);
        return userDetails;
    }
}
